<?php
const NUM = 1;
/**
 * 返回正确数据
 * @description
 * @param array $data
 * @param array $page
 * @param string $code
 * @param string $message
 * @return array
 * @author Mr wang  2019/12/14 下午4:39
 */
function returnRight(array $data = [], array $page = [], $code = '200', string $message = ''): array
{
    if ($message !== '') {
        $message = getConfig('message.' . $code) ?? 'Success';
    }
    $return = ['code' => (string)$code, 'message' => $message, 'data' => $data];
    if (!empty($page)) {
        $return['page_info'] = $page;
    }
    return $return;
}

/**
 * 返回接口错误
 * @description
 * @author Mr wang  2019/12/16 上午9:29
 * @param string $code
 * @param string $message
 * @param array $data
 * @return array
 */
function returnError($code = '1000', string $message = '', array $data = []): array
{
    if ($message == '') {
        $message = getConfig('message.' . $code) ?? 'System error,Please contact the administrator';
    }
    return ['code' => (string)$code, 'message' => $message, 'data' => $data];
}

/**
 * 获取配置文件信息
 * @description
 * @param $fileName
 * @return array|mixed|null
 * @author Mr wang  2019/12/14 下午4:40
 */
function getConfig($fileName)
{
    return \EasySwoole\EasySwoole\Config::getInstance()->getConf($fileName) ?? '';
}

function test(){
    return 10086;
}
